package demo.study;

import java.util.Calendar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class DigitalClock extends Activity {
	View view;
	TextView timeTextView = null;
	Button button;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.digitalclockmain);
		view = this.getCurrentFocus();
		timeTextView = (TextView) this.findViewById(R.id.timeTextView);
		timeTextView.setTextSize(48);
		Message msg = mHandler.obtainMessage(CLOCK);
		mNextTime = SystemClock.uptimeMillis();
		mHandler.sendMessageAtTime(msg, mNextTime);

		button = (Button)findViewById(R.id.button1);
		button.setOnClickListener(new View.OnClickListener() {

			public void onClick(View view) {
				// TODO 自動生成されたメソッド・スタブ
				Intent it = new Intent();
			}
		});


	}

	private static final int CLOCK = 1;
	private long mNextTime;

	private final Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			if (msg.what == CLOCK) {
				long current = SystemClock.uptimeMillis();
				mNextTime = current + 1000;
				msg = obtainMessage(CLOCK);
				sendMessageAtTime(msg, mNextTime);
				String timeStr = String.format("%tT", Calendar.getInstance());
				timeTextView.setText(timeStr);
			}
		}
	};
}
